from flask import Flask, session, request, render_template
import os
from flask_admin import Admin, BaseView, expose
from flask_admin.contrib import sqla
from flask_admin.contrib.sqla import ModelView
from flask_sqlalchemy import SQLAlchemy
from flask_babelex import Babel





app = Flask(__name__)
app.config['SECRET_KEY'] = os.urandom(24)
app.config["SQLALCHEMY_DATABASE_URI"] = 'mysql+pymysql://root:123456@localhost:3306/testadmin'
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db = SQLAlchemy(app)
babel = Babel(app)

app.config['BABEL_DEFAULT_LOCALE'] = 'zh_CN'
class User(db.Model):
    ID = db.Column(db.Integer,primary_key=True)
    abc = db.Column(db.Integer)
    name = db.Column(db.String(20))



admin = Admin(app, name="管理后台")


class MyView(BaseView):
    # 这里类似于app.route()，处理url请求

    @expose('/')
    def index(self):
        return self.render('testajax.html')



admin.add_view(MyView(name=u'Hello'))
admin.add_view(ModelView(User,db.session))


if __name__ == '__main__':
    app.run()
    # user = User()
    # data = user.query.filter_by(abc="asdf").first()
    # print(data is None)